package com.demo.service.impl;

import java.sql.SQLException;

import com.demo.dao.UsersDao;
import com.demo.dao.impl.UsersDaoImpl;
import com.demo.model.Users;
import com.demo.service.UsersService;

public class UsersServiceImpl implements UsersService{
	//利用单例模式调取dao中的对象
	private static UsersDao dao=UsersDaoImpl.getUsersDaoImpl();
	
	//创建service的单例模式
	private static UsersServiceImpl service=new UsersServiceImpl();
	private UsersServiceImpl() {}
	public static UsersServiceImpl getUsersServiceImpl() {
		return service;
	}
	
	@Override
	public boolean tab_users_save(Users user)  {
		// 数据库添加新数据
		String sql="insert into tab_users(id,loginname,username,password) values('"+user.getId()+"','"+user.getLoginname()+"','"+user.getPassword()+"','"+user.getUsername()+"')";
		boolean b=false;
		try {
			b = dao.saveOrUpdate(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return b;
	}

}
